<?php
class SitemapController extends Ext_Controller_Action
{
	
	public function renderAction()
	{
		$this->_helper->layout->disableLayout();
  		$this->getResponse()->clearHeaders();
  		$this->getResponse()->setheader('Content-Type', 'text/xml');
  		
		$sitemap = new Cms_Models_Sitemap();
		$this->view->items = $sitemap->fetchAll();
		$this->view->domain = Zend_Registry::get('config')->app->url;
	}
	
	public function generateAction()
	{
		$node = new Cms_Models_Node();
		$taxonomy = new Cms_Models_Taxonomy();
		
		$sitemap = new Cms_Models_Sitemap();
		$sitemap->delete( '1=1' );
		
		// Agregmos la home
		$row = 	$sitemap->createRow();
		$row->loc = "/" ;
		$row->lastmod = date("Y-mm-dd");
		$row->changefreq = "diarly";
		$row->priority = "0.1";
		$row->save();
		
		
		$nodes = $node->fetchAll( "content_type_id=1 AND locked='F'" )->toArray();
		foreach( $nodes as $n ){
			$row = 	$sitemap->createRow();
			$row->loc = "/node/magazine/nid/" . $n['node_id'];
			$row->lastmod = $n['create_date'];
			$row->changefreq = "monthly";
			$row->priority = "0.2";
			$row->save();
		}
		
		$tax = $taxonomy->fetchAll( 'vocabulary_id = 8' );
		foreach( $tax as $tax) {
			$row = 	$sitemap->createRow();
			$row->loc = "/category/view/tid/" . $t['taxonomy_id'];
			$row->lastmod = date("Y-mm-dd");
			$row->changefreq = "monthly";
			$row->priority = "0.3";
			$row->save();
			
		}
		
		//http://njs.dev/category/view/tid/1
		//http://njs.dev/node/magazine/nid/3
		exit;
		
	}

}